# This file contains the fastlane.tools configuration
# You can find the documentation at https://docs.fastlane.tools
#
# For a list of all available actions, check out
#
#     https://docs.fastlane.tools/actions
#
# For a list of all available plugins, check out
#
#     https://docs.fastlane.tools/plugins/available-plugins
#

# Uncomment the line if you want fastlane to automatically update itself
# update_fastlane

SCHEME = "TestJenkins"
IPA_TIME = Time.now.strftime("%Y%m%d_%H%M")
OUTPUT_DIRECTORY = "build"
ENV_PREFIX=""

default_platform(:ios)

platform :ios do
  before_all do
    xcode_select "/Applications/Xcode.app"
    FASTLANE_XCODEBUILD_SETTINGS_TIMEOUT = "40"
  end

  # development
  lane :iosDevelopment do | option |
    ENV_PREFIX="debug"
    EXPORT_METHOD = "development"
    match(
      git_url: "git@code.shihuo.cn:Xinxin-iOS/certificates.git",
      type: "development",
      git_branch: "xinmei",
      readonly: true,
      app_identifier: "com.ranka.xinxinapp"
    )
    package(configuration: "Debug", buildVersion: "#{option[:buildVersion]}")
  end

  # adhoc
  lane :iosAdHoc do | option |
    ENV_PREFIX="adhoc"
    EXPORT_METHOD = "ad-hoc"
    match(
      git_url: "git@code.shihuo.cn:Xinxin-iOS/certificates.git",
      type: "adhoc",
      git_branch: "xinmei",
      readonly: true,
      app_identifier: "com.ranka.xinxinapp"
    )
    package(configuration: "Debug", buildVersion: "#{option[:buildVersion]}")
  end

  # appstore
  lane :iosAppStore do | option |
    ENV_PREFIX="appstore"
    #app-store,ad-hoc,enterprise,development
    EXPORT_METHOD = "app-store"
    match(
      git_url: "git@code.shihuo.cn:Xinxin-iOS/certificates.git",
      type: "appstore",
      git_branch: "xinmei",
      readonly: true,
      app_identifier: "com.ranka.xinxinapp"
    )
    package(configuration: "Release", buildVersion: "#{option[:buildVersion]}")
  end

  #打包函数
  lane :package do |option|
    cocoapods(use_bundle_exec: false)
    OUTPUT_DIRECTORY = OUTPUT_DIRECTORY + "/#{ENV_PREFIX}" + "/#{option[:buildVersion]}"
    
    gym(
      export_method: "#{EXPORT_METHOD}",
      configuration: option[:configuration],
      output_directory: "#{OUTPUT_DIRECTORY}",
      include_symbols: true,
      include_bitcode: false,
      xcargs: 'DEBUG_INFORMATION_FORMAT="dwarf-with-dsym"',
      export_xcargs: "-allowProvisioningUpdates",
      clean: true,
      silent:true
    )
  end
end